package ${package};

import java.util.List;

import org.junit.Before;
import org.junit.Test;

import ${baseTester};
import ${domain};

public class ${className}DaoTest extends AbstractSpringDaoTest {
	private ${className}Dao <@lowerFirstChar>${className}</@lowerFirstChar>Dao;
	
	protected void injectDependencies() throws Exception {
		super.injectDependencies();
		<@lowerFirstChar>${className}</@lowerFirstChar>Dao = (${className}Dao) this.applicationContext.getBean("<@lowerFirstChar>${className}</@lowerFirstChar>Dao");
	}
	@Before
	public void setBefore() {
		
	}
	//write parameters set, db operations: insert,update,delete
	public ${className}  setWrite${className}(){
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = new ${className}();
		//TODO set
		<#list columns as column>
		<@lowerFirstChar>${className}</@lowerFirstChar>.set<@upperFirstChar>${column.javaName}</@upperFirstChar>(null) ; 
		</#list>
		return <@lowerFirstChar>${className}</@lowerFirstChar>;
	}
	//read parameters set, db operations: select
	public ${className}  setRead${className}(){
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = new ${className}();
		//TODO set
		<#list columns as column>
		<@lowerFirstChar>${className}</@lowerFirstChar>.set<@upperFirstChar>${column.javaName}</@upperFirstChar>(null) ; 
		</#list>
		return <@lowerFirstChar>${className}</@lowerFirstChar>;
	}
	
	 @Test
	public void testAdd${className}() {
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = this.setWrite${className}();
		<@lowerFirstChar>${className}</@lowerFirstChar>Dao.add${className}(<@lowerFirstChar>${className}</@lowerFirstChar>);		
	}
	
    @Test
	public void testDel${className}() {
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = this.setWrite${className}();
		<@lowerFirstChar>${className}</@lowerFirstChar>Dao.del${className}(<@lowerFirstChar>${className}</@lowerFirstChar>);
	}

    @Test
	public void testUpdate${className}() {
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = this.setWrite${className}();
		<@lowerFirstChar>${className}</@lowerFirstChar>Dao.del${className}(<@lowerFirstChar>${className}</@lowerFirstChar>);
	}
	
	 @Test
	public void testFind${className}() {
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = this.setRead${className}();
		<@lowerFirstChar>${className}</@lowerFirstChar> = <@lowerFirstChar>${className}</@lowerFirstChar>Dao.find${className}(<@lowerFirstChar>${className}</@lowerFirstChar>);
		<#list columns as column>
		<#if column_index ==0>
		assertEquals(1, <@lowerFirstChar>${className}</@lowerFirstChar>.get<@upperFirstChar>${column.javaName}</@upperFirstChar>().intValue());
		<#break>
		</#if>
		</#list>
	}
	
    @Test
	public void testList${className}() {
		${className} <@lowerFirstChar>${className}</@lowerFirstChar> = this.setRead${className}();
		List<${className}>  <@lowerFirstChar>${className}</@lowerFirstChar>s = <@lowerFirstChar>${className}</@lowerFirstChar>Dao.list${className}(<@lowerFirstChar>${className}</@lowerFirstChar>);
		for(${className} <@lowerFirstChar>${className}</@lowerFirstChar>tmp :  <@lowerFirstChar>${className}</@lowerFirstChar>s) {
			assertNotNull(<@lowerFirstChar>${className}</@lowerFirstChar>tmp);
		}
		assertTrue(<@lowerFirstChar>${className}</@lowerFirstChar>s.size() > 0);
		
		Integer count = <@lowerFirstChar>${className}</@lowerFirstChar>Dao.list${className}Count(<@lowerFirstChar>${className}</@lowerFirstChar>);
		assertTrue(count > 0);
	}
	
}

